<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>订单信息</title>
    <link href="css/swiper-5.4.5/swiper.min.css" rel="stylesheet">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/my.css" rel="stylesheet">
    <link href="css/font-awesome.css" rel="stylesheet">
    <style>
        .nx-nav-container ul{
            width: 100%;
            height: 100%;
            margin: 0 auto;
            display: flex;
            justify-content: center;
        }
        .nx-nav-container ul li{
            display: inline-block;
            width: 120px;
            text-align: center;
            line-height: 45px;
        }
        .nx-nav-container a{
            color: #FFFFFF;
        }
        .nx-nav-container a:hover {
            color: aquamarine;
            text-decoration: none;
        }
        td {
            vertical-align: middle! important;
        }
        .left-box{
            width: 100%;
            height: 400px;
            background-color: #FFFFFF;
        }
        .img-item-box{
            width: 100%;
            height: 90px;
            margin-top: 10px;
        }
        .right-box{
            width: 100%;
            height: 400px;
            background-color: #FFFFFF;
        }

        .right-title{
            font-size: 20px;
            font-weight: bold;
        }
        .right-box li{
            padding: 10px 40px;
        }
        .praise{
            cursor: pointer;
            font-size: 20px;
            margin-left: 10px;
        }
    </style>
</head>
<body>
<div id="wrapper">
    <div class="nx-header">
        <div style="display: flex;width: 100%;height: 30px;line-height: 30px;background-color: #eee;">
            <div style="flex: 5;padding: 0 10px; color: orangered;">
                欢迎访问 电影订票购票系统
            </div>
            <div v-if="user.name" style="flex: 1">
                欢迎您： {{user.name}}
                <a style="margin-left: 30px;color: blue;" href="javascript:void(0);" @click="logout">退出</a>
            </div>
        </div>
    </div>

    <div style="height: 80px; line-height: 80px;">
        <div style="margin-left: 20px;position: relative;">
            <img src="img/logo1.png" style="width: 40px;position: absolute;top: 20px;">
            <b style="margin-left: 45px;font-size:25px;text-shadow: 5px 5px 3px #888888">电影订票购票系统</b>
        </div>
    </div>

    <div class="nx-nav-container" style="height: 45px;background-color: black;">
        <ul>
            <li><a href="index.html">首页</a></li>
            <li><a href="advertiserInfo.html">公告信息</a></li>
            <li><a href="messageInfo.html">在线交流信息</a></li>
            <li><a href="linkInfo.html">友情链接</a></li>
            <li><a href="cartInfo.html">收藏栏信息</a></li>
            <li class="active"><a href="orderInfo.html">订单信息</a></li>
            <li><a href="commonInfo.html">评价信息</a></li>
            <li><a href="javascript:void(0)" @click="personalPage">个人信息</a></li>
            <li v-if="isShow"><a href="/end/page/index.html" target="_blank">进入后台系统</a></li>
            <li v-if="!isLogin"><a href="/end/page/login.html" target="_blank">登录</a></li>
            <li v-if="!isLogin"><a href="/end/page/register.html" target="_blank">注册</a></li>
        </ul>
    </div>

    <div class="container" style="margin-top: 20px;">
        <div class="col-md-12">
            <table class="table table-striped table-bordered table-hover">
                <thead>
                     <tr style="background-color: #cccccc">
                        <th>商品</th>
                        <th>订单编号</th>
                        <th>金额(元)</th>
                        <th>收货人</th>
                        <th>联系方式</th>
                        <th>时间</th>
                        <th>状态</th>
                        <th>操作</th>
                     </tr>
                </thead>
                <tbody>
                    <tr v-for="(item, index) in orderData" :key="item.id">
                        <td style="width: 230px;">
                            <div v-for="g in item.goodsList" style="margin-bottom: 5px;display: flex;align-items: center">
                                < img style="width: 50%;height: 50%;" :src=g.imgSrc>
                                <span style="font-size: 12px;margin-left:10px;">{{g.name}} X {{g.num}}</span>
                            </div>
                        </td>
                        <td>{{item.orderId}}</td>
                        <td>{{item.totalPrice}}</td>
                        <td>{{item.linkMan}}</td>
                        <td>{{item.linkPhone}}</td>
                        <td>{{item.createTime}}</td>
                        <td>{{item.status}}</td>
                        <td>
                            <button v-if="item.status ==='待付款'||item.status ==='完成'|| item.status ==='已退款'" class="btn btn-danger btn-xs"@click="del(item)">删除</button>
                            <button v-if="item.status ==='待付款'" class="btn btn-warning btn-xs"@click="changeStatus(item.id,'已取消')">取消</button>
                            <button v-if="item.status ==='待付款'" class="btn btn-primary btn-xs"@click="changeStatus(item.id,'待观看')">付款</button>
                            <button v-if="item.status ==='待观看'" class="btn btn-primary btn-xs"@click="changeStatus(item.id,'已退款')">退款</button>
                         </td>
                    </tr>
                </tbody>
            </table>
            <div style="text-align: center;">
                <nav>
                    <ul class="pagination">
                        <li class="page-item" :class="{disabled:preActive}">
                            <a class="page-link" href="javascript:void(0)" @click="loadOrderInfo(pageInfo.pageNum - 1)">上一页</a>
                        </li>
                        <li class="page-item" :class="{disabled:preActive}">
                            <a class="page-link" href="javascript:void(0)" v-if="pageInfo.pageNum > 1"
                               @click="loadOrderinfo(pageInfo.pageNum - 1)">{{pageInfo.pageNum - 1}}</a>
                        </li>
                        <li class="page-item disabled">
                            <a class="page-link" href="javascript:void(0)" >{{pageInfo.pageNum}}</a>
                        </li>

                        <li class="page-item">
                            <a class="page-link" href="javascript:void(0)" v-if="pageInfo.hasNextPage"
                               @click="loadOrderinfo(pageInfo.hasNextPage?(pageInfo.pageNum + 1):pageInfo.pageNum)">{{pageInfo.pageNum + 1}}</a>
                        </li>
                        <li class="page-item" :class="{disabled:nextActive}">
                            <a class="page-link" href="javascript:void(0)"
                               @click="loadOrderinfo(pageInfo.hasNextPage?(pageInfo.pageNum + 1):pageInfo.pageNum)">下一页</a>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</div>
<script src="js/jquery-1.10.2.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/swiper-5.4.5/swiper.min.js"></script>
<script src="js/vue2.6.11/vue.min.js"></script>
<script src="js/vue2.6.11/axios.js"></script>
<script src="js/my.js"></script>
<script>
    new Vue({
        el: "#wrapper",
        data: {
            user: {}, // 当前登录用户
            isShow: false, // 是否显示进入后台
            isLogin: false, // 是否登录
            orderData: [],  //订单列表
            pageInfo: {},   //翻页信息
            preActive: true,  //是否有上一页,true表示没有,false表示有
            nextActive: true  //是否有下一页,true表示没有,false表示有
        },
        created: function () {
            this.loadOrderInfo(1);

        },
        methods: {
            //加载订单列表
            loadOrderInfo(pageNum){
                // 查询权限
                axios.get('/auth').then(res => {
                    if (res.data.code == '0') {
                        this.user = res.data.data;
                        // 若是管理员
                        if (this.user.level === 1) {
                            // 显示可以进入后台
                            this.isShow = true;
                        }
                        this.isLogin = true;
                        // 获取订单列表
                        axios.get("/orderInfo/page/front?userId=" + this.user.id + "&level=" + this.user.level + "&pageNum=" + pageNum).then((res) => {
                             if (res.data.code === '0') {
                                let orderData = res.data.data.list;
                                orderData.forEach((item) => {
                                    let goodsList = item.goodsList;
                                    goodsList.forEach((g) => {
                                        // 获取展示图
                                        g.imgSrc = '/front/img/goods/default.png';
                                        if (g.fields) {
                                            let fields1 = JSON.parse(g.fields);
                                            if (fields1.length) {
                                                g.imgSrc = '/files/download/' + fields1[0];
                                            }
                                        }
                                    });
                                    item.goodsList = goodsList;
                                });
                                this.orderData = orderData;
                                this.pageInfo = res.data.data;
                                this.preActive =!(this.pageInfo.hasPreviousPage);
                                this.nextActive =!(this.pageInfo.hasNextPage);
                            } else {
                                alert(res.data.msg);
                            }
                        });




                    }else {
                        alert("请先登录");
                        location.href = '/end/page/login.html';
                    }
                });
            },

            //删除某个订单
            del(data){
                if(confirm('确定删除订单信息吗？')){
                    axios.delete('/orderInfo/'+data.id).then(res=>{
                        if(res.data.code === '0'){
                            alert('删除成功');
                            this.loadOrderInfo(1);
                        }else{
                            alert(res.data.msg);
                        }
                    });
                }
            },
            
            //修改订单信息
            changeStatus(id,status){
                axios.post('/orderInfo/status/'+id+'/'+status).then(res =>{
                        if(res.data.code === '0'){
                            this.loadOrderInfo(1);
                        }else{
                            alert(res.data.msg);
                        }

                });
            },
            
            
            logout(){
                axios.get('/logout').then(res =>{
                    if(res.data.code === '0'){
                        location.href = '/front/index.html';
                    }else{
                        alert(res.data.msg);
                    }
                });
            },
        }
    });
</script>
</body>
</html>
